// pages/dpcp/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:'',
    active:0,
    types:["润肺抗燥","补血","清热祛火","减肥","美容"],
    curList:[],
    list:app.globalData.cpList
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    that.getCurList();
  },
  onClear:function(){
    var that = this;
    that.setData({
      value:""
    })
    that.getCurList();
  },
  onSearch:function(e){
    console.log(e)
    var that = this;
    var value = e.detail;
    that.setData({
      value:value
    })
    that.getCurList();
  },
  onChange:function(e){
    var that = this;
    var index = e.detail.index;
    that.setData({
      active:parseInt(index)
    })
    that.getCurList();
  },
  //获取列表
  getCurList:function(){
    let that = this;
    let types = that.data.types;
    let list = that.data.list;
    let active = that.data.active;
    let curType = types[active];
    let value = that.data.value;
    let curList = list.filter(item => {
      if(value){
        if(item.cpName.indexOf(value) > -1 && item.type_v3 == curType){
          return item
        }
      }else{
        if(item.type_v3 == curType){
          return item
        }
      }
    })
    that.setData({
      curList:curList
    })

  },
  onClick:function(item){
    wx.setStorageSync('curCP', item.currentTarget.dataset.item);
    wx.navigateTo({
      url: '/pages/cp_detail/index',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})